﻿using System;
using System.Collections.Generic;
using System.Linq;

using btmerc.API.Schemas.Interfaces;

namespace btmerc.API.Schemas
{
    public partial class GeneralContractModifiers : IGeneralContractModifiers
    {
        private Dictionary<Rating, ContractModifiers> _dragoonsRatingModifiers;
        private Dictionary<TroopType, ContractModifiers> _forceTypeModifiers;
        private Dictionary<HiringHall, ContractModifiers> _hiringHallModifiers;

        public GeneralContractModifiers()
        {
            this.dragoonsRatingsField = new DragoonsRatings();
            this.forceTypesField = new ForceTypes();
            this.hiringHallsField = new HiringHalls();

            _dragoonsRatingModifiers = dragoonsRatingsField.DragoonsRating.ToDictionary(m => m.DragoonsRating, m => (ContractModifiers)m);
            _forceTypeModifiers = forceTypesField.ForceType.ToDictionary(m => m.MainForceType, m => (ContractModifiers)m);
            _hiringHallModifiers = hiringHallsField.HiringHall.ToDictionary(m => (HiringHall)Enum.Parse(typeof(HiringHall), m.Name), m => (ContractModifiers)m);
        }

        public short GetOfferModifier(TroopType type, Rating dragoonsRating, HiringHall hiringHall)
        {
            return (short)(_dragoonsRatingModifiers[dragoonsRating].OffersModifier + 
                           _forceTypeModifiers[type].OffersModifier + 
                           _hiringHallModifiers[hiringHall].OffersModifier);
        }

        public short GetEmployerModifier(TroopType type, Rating dragoonsRating, HiringHall hiringHall)
        {
            return (short)(_dragoonsRatingModifiers[dragoonsRating].EmployersModifier +
                           _forceTypeModifiers[type].EmployersModifier +
                           _hiringHallModifiers[hiringHall].EmployersModifier);
        }

        public short GetMissionModifier(TroopType type, Rating dragoonsRating, HiringHall hiringHall)
        {
            return (short)(_dragoonsRatingModifiers[dragoonsRating].MissionsModifier +
                           _forceTypeModifiers[type].MissionsModifier +
                           _hiringHallModifiers[hiringHall].MissionsModifier);
        }
    }
}
